(async() => {
    let koa = require("koa");
    const mongoose = require('mongoose');
    const KoaRouter = require('koa-router');
    let app = new koa();


    mongoose.connect('mongodb://databasel:27017/study', {
        useUnifiedTopology: true,
        useNewUrlParser: true,
        useCreateIndex: true
    })

    // const { MongoClient } = require('mongodb');

    // //创建客户端
    // const client = new MongoClient("mongodb://localhost:27016", {

    //     useNewUrlParser: true,
    //     useUnifiedTopology: true
    // });

    const router = new KoaRouter();

    //注册路由
    router.get('/', async(ctx, next) => {
        console.log('index');
        ctx.body = 'index';
    });

    router.get('/test', async(ctx, next) => {
        console.log("执行")
        const Fruit = require('./Fruit');
        let result = await Fruit.findOne();
        console.log("libing", result)
        ctx.body = {
            result
        }
    });

    app.use(router.routes()); // 添加路由中间件
    app.use(router.allowedMethods()); // 对请求进行一些限制处理

    app.listen(3100, () => {
        console.log("这是 localhost:3100")
    })

})()